<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/inc/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>内容管理</title>
<meta name="decorator" content="main" />

<script type="text/javascript">
	$(function() {
		$('#dg').datagrid({
			url : '${ctx}/content/ContentOptHandleServlet.do',
			toolbar : '#OptMenu',
			columns : [ [ {
				checkbox : true
			}, {
				field : 'title',
				title : '标题'
			}, {
				field : 'columnname',
				title : '所属栏目'
			}, {
				field : 'constatus',
				title : '状态',
				formatter : function(value, row, index) {
					if (value == 'Y') {
						return '已发布';
					}
					if (value == 'N') {
						return '未发布'
					}
				}
			}, {
				field : 'orderscore',
				title : '权重',
				sorter : function(a, b) {
					alert('a=' + a);
					alert('b=' + b);
					a = a.split('/');
					b = b.split('/');
					if (a[2] == b[2]) {
						if (a[0] == b[0]) {
							return (a[1] > b[1] ? 1 : -1);
						} else {
							return (a[0] > b[0] ? 1 : -1);
						}
					} else {
						return (a[2] > b[2] ? 1 : -1);
					}
				}
			}, {
				field : 'keyword',
				title : '关键字'
			}, {
				field : 'createautor',
				title : '作者'
			}, {
				field : 'id',
				title : '操作',
				align : 'center',
				formatter : function(value, row, index) {
					return "<a href=${ctx }/content/ContentOptHandleServlet.do?method=editContent&id="+value+">编辑</a>&emsp;&emsp;<a onclick=confirmdelete("+value+")"+">删除</a>";
				}
			}, ] ],
			pagination : true,
			rownumbers : true,
			checkOnSelect : true,
			striped : true,
			loadMsg : '臣妾正在努力加载数据，官人莫着急',
			pageList : [ 1, 2, 3, 10, 20, 30, 40, 50 ],
			queryParams : {
				name : 'easyui',
				subject : 'datagrid'
			},
			showHeader : true,
			rowStyler : function(index, row) {
				if (row.constatus == 'Y') {
					return 'color:green;';
				}
				if (row.constatus == 'N') {
					return 'color:red;';
				}
			},
			sortName : "orderscore",
			sortOrder : 'asc'
		});

	});
	function confirmdelete(value){
		$.messager.confirm('确认','您确认想要删除记录吗？',function(r){    
		    if (r){    
		    	window.location.href="${ctx }/content/ContentOptHandleServlet.do?method=delContent&id="+value;
		    }    
		});
		
	}
	
</script>
<script type="text/javascript">
	function addOpt() {
		window.location.href = "${ctx }/content/ContentOptHandleServlet.do?method=addContent";
	}
	function editOpt() {
		//alert("您点击了编辑按钮");
		
		var selected=$('#dg').datagrid("getSelected");
		if(selected==null)
		{
		  alert("您没有选择任何元素");
		}
		console.info(selected);
		//alert("您点击了编辑按钮");
		window.location.href = "${ctx }/content/ContentOptHandleServlet.do?method=editContent&id="+selected.id;
	}
	function delOpt() {
		window.location.href = "${ctx }/content/ContentOptHandleServlet.do?method=delContent";
	}
	function helpOpt() {
		$.messager.alert('关于我们', '点击新增，编辑，删除按钮可以实现你想要的功能！', 'info');
	}
</script>

</head>
<body>
<ul class="breadcrumbs">
		<li><a href="${ctx}/login/LoginIndexRequestServlet.do"><i class="iconfa-home"></i></a> <span
			class="separator"></span></li>
		<li>内容管理</li>
</ul>
	<div class="maincontent">
		<div class="maincontentinner">
			<div class="row-fluid">
				<div class="span12">
					<div class="widget">
						<h4 class="widgettitle">内容列表</h4>
						<div class="widgetcontent">
							<table id="dg"></table>
							<div id="OptMenu">
							
							 <c:forEach var="menu" items="${sessionScope.menu}">
								<c:set value="${menu.list}" var ="list" />
									<c:if test="${menu.menuIno.menuId==5}">
										<c:forEach var="items" items="${menu.list}">
											<c:if test="${items.menuId==16}">
											   <a onclick='addOpt()' class="easyui-linkbutton"	   data-options="iconCls:'icon-add',plain:true">新增</a>
											</c:if>
											<c:if test="${items.menuId==17}">
											 <a onclick='editOpt()' class="easyui-linkbutton"	data-options="iconCls:'icon-edit',plain:true">编辑</a>
											</c:if>
								        </c:forEach>
									</c:if>
							</c:forEach>
							    <a onclick='helpOpt()' class="easyui-linkbutton"	data-options="iconCls:'icon-help',plain:true">帮助</a>
							</div>

						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

</body>
</html>